﻿using System;

using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
	/// <summary>
	/// Summary description for AccessControl.
	/// </summary>
	public class ESCAccessControl: AccessControl
	{

		public override bool IsReadOnly
		{
			get
			{
				if( base.IsReadOnly )
				{
					return base.IsReadOnly;
				}
				else
				{
					if( this._currentStep == WorkTransition.ESC_CloseApp || this._currentStep == WorkTransition.ESC_CostCenterHeadApproval
						|| this._currentStep == WorkTransition.ESC_DeptHeadApproval || this._currentStep == WorkTransition.ESC_ESCHeadApproval
						|| this._currentStep == WorkTransition.ESC_FNCApproval || this._currentStep == WorkTransition.ESC_ESCSurvey )
					{
						return true;
					}
					else
						return false;
				}
			}
		}

		public override bool IsAttachmentReadOnly
		{
			get
			{
				if(_state == SysDicItem.ProjectStatusFlag.NORMAL || _state == null || _state == string.Empty)
				{
					if( this._currentStep == WorkTransition.ESC_CostCenterHeadApproval || this._currentStep == WorkTransition.ESC_DeptHeadApproval
						|| this._currentStep == WorkTransition.ESC_FNCApproval || this._currentStep == WorkTransition.ESC_ESCHeadApproval
						|| this._currentStep == WorkTransition.ESC_ESCSurvey )
					{
						return true;
					}
				}

				if(this._currentStep == WorkTransition.End && this._state!=SysDicItem.ProjectStatusFlag.Archive)
				{
					if(_state == SysDicItem.ProjectStatusFlag.Participation)
						return !this._isMgrOrStaff;
					else
						return true;
				}
				else
					return base.IsAttachmentReadOnly;
				
			}
		}

		public override bool IsButtonVisible(string name)
		{
			if(this.IsQuery)
			{
				switch(name)
				{
					case ESCTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case ESCTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					case ESCTransitionList.Save:
						return this.ShowSaveButton();
						break;
					default:
						return false;
				}
			}
			else
			{
				switch(name)
				{
					case ESCTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case ESCTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					default:
					switch(this._currentStep)
					{
						case WorkTransition.Draft:
							if(name == ESCTransitionList.Submit || name == ESCTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.ESC_Request:
							if(name == ESCTransitionList.Submit || name == ESCTransitionList.Save || name == ESCTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.ESC_ReRequest:
							if(name == ESCTransitionList.Submit || name == ESCTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.ESC_AssignApp:
							if(name == ESCTransitionList.Assign || name == ESCTransitionList.Reject || name == ESCTransitionList.Save
								|| name == ESCTransitionList.Check || name == ESCTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.ESC_CheckApp:
							if(name == ESCTransitionList.Reject || name == ESCTransitionList.Check || name == ESCTransitionList.Query
								|| name == ESCTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.ESC_CostCenterHeadApproval:
							if( name == ESCTransitionList.Reject || name == ESCTransitionList.Approve || name == ESCTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.ESC_DeptHeadApproval:
							if( name == ESCTransitionList.Reject || name == ESCTransitionList.Approve || name == ESCTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.ESC_ESCHeadApproval:
							if( name == ESCTransitionList.Reject || name == ESCTransitionList.Approve || name == ESCTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.ESC_FNCApproval:
							if( name == ESCTransitionList.Reject || name == ESCTransitionList.Approve || name == ESCTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.ESC_ESCSurvey:
							if( name == ESCTransitionList.Save || name == ESCTransitionList.Submit || name == ESCTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.ESC_CloseApp:
							if( name == ESCTransitionList.Save || name == ESCTransitionList.Close)// || name == OCRTransitionList.Query)
								return true;
							else
								return false;
					}
						return false;
						break;
				}
			}
		}
		
	}	
}

